package main

import (
    "facecat"
    "fmt"
    "io/ioutil"
)

/*
* 重绘背景的实现方法
* view:视图
* paint:绘图对象
* clipRect:裁剪区域
*/
func OnPaint(view *facecat.FCView, paint *facecat.FCPaint, clipRect facecat.FCRect) {
    if view.ViewName == "Button4" {
        paint.FillRect("rgb(255,0,0)", 0, 0, view.Size.Cx, view.Size.Cy);
    }else{
        facecat.OnPaintDefault(view, paint, clipRect)
    }
}

/*
* 重绘边框的实现方法
* view:视图
* paint:绘图对象
* clipRect:裁剪区域
*/
func OnPaintBorder(view *facecat.FCView, paint *facecat.FCPaint, clipRect facecat.FCRect) {
    facecat.OnPaintBorderDefault(view, paint, clipRect)
}

/*
*视图的鼠标移动方法
*view 视图
*mp 坐标
*buttons 按钮 0未按下 1左键 2右键
*clicks 点击次数
*delta 滚轮值
*/
func OnMouseMove(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int){
    facecat.OnMouseMoveDefault(view, mp, buttons, clicks, delta)
}

/*
*视图的鼠标按下方法
*view 视图
*mp 坐标
*buttons 按钮 0未按下 1左键 2右键
*clicks 点击次数
*delta 滚轮值
*/
func OnMouseDown(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int){
	facecat.OnMouseDownDefault(view, mp, buttons, clicks, delta)
}

/*
*视图的鼠标抬起方法
*view 视图
*mp 坐标
*buttons 按钮 0未按下 1左键 2右键
*clicks 点击次数
*delta 滚轮值
*/
func OnMouseUp(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int){
    facecat.OnMouseUpDefault(view, mp, buttons, clicks, delta)
}

/*
* 鼠标点击实现方法
* view: 图层
* firstTouch:是否第一次触摸
* firstPoint:第一次触摸的坐标
* secondTouch:是否第二次触摸
* secondPoint:第二次触摸的坐标
* clicks:点击次数
*/
func OnClick(view *facecat.FCView, firstTouch bool, firstPoint facecat.FCPoint, secondTouch bool, secondPoint facecat.FCPoint, clicks int){
    facecat.OnClickDefault(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks)
    if view.ViewName == "Button" {
        fmt.Println(view.Text)
    } else if view.ViewName == "Button2" {
        fmt.Println(view.Text)
    } else if view.ViewName == "Button3"{
        fmt.Println(view.Text)
    } else if view.ViewName == "Button4" {
        fmt.Println(view.Text)
    }
}

/*
* 鼠标滚动实现方法
* view:视图
* mp:坐标
* button:按钮
* clicks:点击次数
* delta:滚轮值
*/
func OnMouseWheel(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int) {
    facecat.OnMouseWheelDefault(view, mp, buttons, clicks, delta)
}

/*
* 鼠标离开实现方法
* view:视图
* mp:坐标
* button:按钮
* clicks:点击次数
* delta:滚轮值
*/
func OnMouseLeave(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int) {
    facecat.OnMouseWheelDefault(view, mp, buttons, clicks, delta)
}

/*
* 鼠标进入实现方法
* view:视图
* mp:坐标
* button:按钮
* clicks:点击次数
* delta:滚轮值
*/
func OnMouseEnter(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int) {
    facecat.OnMouseWheelDefault(view, mp, buttons, clicks, delta)
}

/*
* 键盘按下
* view:视图
* key:按键
*/
func OnKeyDown(view *facecat.FCView, key int){

}

/*
* 键盘抬起
* view:视图
* key:按键
*/
func OnKeyUp(view *facecat.FCView, key int){
}

/*
* 更新悬浮状态
* views:视图集合
*/
func UpdateView(views []*facecat.FCView) {
    facecat.UpdateViewDefault(views)
}

var appPaint = new(facecat.FCPaint)

func WndProc(hwnd facecat.HWND, msg uint32, wParam, lParam uintptr) (result uintptr) {
    return facecat.WndProcDefault(appPaint, hwnd, msg, wParam, lParam)
}

func main() {
    appPaint = facecat.CreatePaint()
    appPaint.OnPaint = OnPaint
    appPaint.OnPaintBorder = OnPaintBorder
    appPaint.OnMouseDown = OnMouseDown
    appPaint.OnMouseMove = OnMouseMove
    appPaint.OnMouseUp = OnMouseUp
    appPaint.OnMouseWheel = OnMouseWheel
    appPaint.OnClick = OnClick
    appPaint.OnUpdateView = UpdateView
    appPaint.OnMouseLeave = OnMouseLeave
    appPaint.OnMouseEnter = OnMouseEnter
    appPaint.OnKeyDown = OnKeyDown
    appPaint.OnKeyUp = OnKeyUp
    facecat.CreateMainWindow(appPaint, "FaceCat-Go", WndProc)
    xmlStr, _ := ioutil.ReadFile("xml//buttonexample.xml")
    facecat.RenderFaceCat(appPaint, string(xmlStr))
    tabPage := facecat.FindViewByName("TabPage2", appPaint.Views);
    button := facecat.CreateView("button")
    button.Location = facecat.CreatePoint(100, 100)
    button.Size = facecat.CreateSize(100, 20)
    facecat.AddViewToParent(button, tabPage)
    button.Text = "确定"
    facecat.ShowWindow(appPaint)
}